//
//  ZPTeacherDetailViewController.m
//  ZPIOSEducation
//
//  Created by Encoder on 17/1/13.
//  Copyright © 2017年 mini1. All rights reserved.
//
#import "CusBtn.h"
#import <UShareUI/UMSocialUIManager.h>
#import "ZPTeacherDetailViewController.h"
#import "ZPTDTableViewCell00.h"
#import "ZPTDTableViewCell01.h"
#import "ZPTDTableViewCell02.h"
#import "ZPTDTableViewCell03.h"
#import "HomeCommunityCell.h"
#import "ZPTeacherCmmTableViewCell.h"
#import "ZPTDTableViewCell11.h"
#import "ZPTDTableViewCell12.h"
#import "ZPTeacherCommentViewController.h"
#import "ComfirmOrderViewController.h"
#import "KeBiaoViewController.h"
#import "TeacherInfoViewController.h"
#import "ZPRegisterLoginViewController.h"
#import "ZPBaseNavigationController.h"
#import "HonourViewController.h"

@interface ZPTeacherDetailViewController ()<UITableViewDelegate,UITableViewDataSource,ZPTDTableViewCell11Delegate,ZPTDTableViewCell01Delegate,UIWebViewDelegate>{
    
    __weak IBOutlet UILabel *stuCount;
    __weak IBOutlet UIImageView *headUrl;
    __weak IBOutlet UILabel *teacherName;
    __weak IBOutlet UILabel *active;
    __weak IBOutlet UILabel *autograph;
    __weak IBOutlet UILabel *classPercent;
    __weak IBOutlet UILabel *quitPercent;
    __weak IBOutlet UILabel *totalScore;
    __weak IBOutlet UILabel *constellation;
    __weak IBOutlet UILabel *enrollsPercent;
    MBProgressHUD *hud;
    NSDictionary *teacherHome;
    NSArray *honourDArr;
    NSArray *pingjiaArr;
    UIWebView  *cellWebView;
    __weak IBOutlet UIImageView *TSex;

}
@property (strong, nonatomic) IBOutlet UIView *THeaderView;
@property (strong, nonatomic) IBOutlet UIView *SHeaderView;
@property (weak, nonatomic) IBOutlet UITableView *detailTableView;
@property (weak, nonatomic) IBOutlet CusBtn *mainBtn;
@property (weak, nonatomic) IBOutlet CusBtn *courseBtn;

@property (assign,nonatomic) BOOL isShowingMainTable;
@property (strong,nonatomic) NSMutableArray *tableData;
@property (strong,nonatomic) NSArray *courseTableArray;
@property (copy,nonatomic) NSString *phone;
@end

@implementation ZPTeacherDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    hud = [[MBProgressHUD alloc]initWithView:self.view];
    [self.view addSubview:hud];
    _tableData = [NSMutableArray array];
    _courseTableArray = [NSArray array];
//    _tableData = [[NSArray arrayWithObjects:
//                   //[NSMutableDictionary dictionaryWithObjectsAndKeys:@"Info",@"type",nil],
//                   //[NSMutableDictionary dictionaryWithObjectsAndKeys:@"SHead",@"type",nil],
//                   //[NSMutableDictionary dictionary],
//                   //[NSMutableDictionary dictionary],
////                   [NSMutableDictionary dictionaryWithObjectsAndKeys:@"SHead",@"type",nil],
////                   [NSMutableDictionary dictionaryWithObjectsAndKeys:@"DiDian",@"type",nil],
////                   [NSMutableDictionary dictionaryWithObjectsAndKeys:@"DiDian",@"type",nil],
////                   [NSMutableDictionary dictionaryWithObjectsAndKeys:@"SHead",@"type",nil],
////                   [NSMutableDictionary dictionaryWithObjectsAndKeys:@"PingJia",@"type",nil],
////                   [NSMutableDictionary dictionaryWithObjectsAndKeys:@"PingJia",@"type",nil],
////                   [NSMutableDictionary dictionaryWithObjectsAndKeys:@"SHead",@"type",nil],
////                   [NSMutableDictionary dictionaryWithObjectsAndKeys:@"SheQu",@"type",nil],
////                   [NSMutableDictionary dictionaryWithObjectsAndKeys:@"SheQu",@"type",nil],
//                   nil] mutableCopy];
    
    
    
    UIBarButtonItem *b1=[[UIBarButtonItem alloc]initWithImage:Z_IMAGE(@"分享图标") style:UIBarButtonItemStylePlain target:self action:@selector(shareAction)];
    UIBarButtonItem *b2=[[UIBarButtonItem alloc]initWithImage:Z_IMAGE(@"客服电话切片") style:UIBarButtonItemStylePlain target:self action:@selector(dailPhone)];
    self.navigationItem.rightBarButtonItems = @[b1,b2];
    
    cellWebView = [[UIWebView  alloc] initWithFrame:CGRectMake(3, 0, SCREENWIDTH - 6, 214)];
    cellWebView.delegate = self;
    cellWebView.scrollView.scrollEnabled = NO;
    NSURLRequest  *request = [NSURLRequest  requestWithURL:[NSURL  URLWithString:[NSString stringWithFormat:APITeacherDetail,_teacherId]]];
    [cellWebView  loadRequest:request];
    
    _isShowingMainTable = YES;
    _detailTableView.tableHeaderView = self.THeaderView;
    [_detailTableView registerNib:[UINib nibWithNibName:@"ZPTDTableViewCell00" bundle:nil] forCellReuseIdentifier:@"ZPTDTableViewCell00"];
    [_detailTableView registerNib:[UINib nibWithNibName:@"ZPTDTableViewCell01" bundle:nil] forCellReuseIdentifier:@"ZPTDTableViewCell01"];
    [_detailTableView registerNib:[UINib nibWithNibName:@"ZPTDTableViewCell02" bundle:nil] forCellReuseIdentifier:@"ZPTDTableViewCell02"];
    [_detailTableView registerNib:[UINib nibWithNibName:@"ZPTDTableViewCell03" bundle:nil] forCellReuseIdentifier:@"ZPTDTableViewCell03"];
    [_detailTableView registerNib:[UINib nibWithNibName:@"HomeCommunityCell" bundle:nil] forCellReuseIdentifier:@"HomeCommunityCell"];
    [_detailTableView registerNib:[UINib nibWithNibName:@"ZPTeacherCmmTableViewCell" bundle:nil] forCellReuseIdentifier:@"ZPTeacherCmmTableViewCell"];
    [_detailTableView registerNib:[UINib nibWithNibName:@"ZPTDTableViewCell11" bundle:nil] forCellReuseIdentifier:@"ZPTDTableViewCell11"];
    [_detailTableView registerNib:[UINib nibWithNibName:@"ZPTDTableViewCell12" bundle:nil] forCellReuseIdentifier:@"ZPTDTableViewCell12"];
    [_detailTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
    [self switchBtn:_mainBtn];
    [self.view setNeedsUpdateConstraints];
    [self getteacherbase];
}



-(void)shareAction{

    [UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_WechatSession),@(UMSocialPlatformType_WechatTimeLine)]];
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        if (platformType==UMSocialPlatformType_UserDefine_Begin+2) {
            [UIPasteboard generalPasteboard].string = [NSString stringWithFormat:APITeacherShequ,_teacherId];
            [ZPPromptView showMessage:@"复制成功"];
        }else if (platformType==UMSocialPlatformType_WechatSession){
            UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
            
            UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:[NSString stringWithFormat:@"%@老师 - 石头培优教育",teacherName.text] descr:autograph.text thumImage:[UIImage imageNamed:@"shareIcon"]];
            shareObject.webpageUrl =[NSString stringWithFormat:APITeacherShequ,_teacherId];
            messageObject.shareObject = shareObject;

            //调用分享接口
            [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
                if (error) {
                    NSLog(@"************Share fail with error %@*********",error);
                }else{
                    NSLog(@"response data is %@",data);
                }
            }];
        }else if (platformType==UMSocialPlatformType_WechatTimeLine){
            UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
            messageObject.text = [NSString stringWithFormat:APITeacherShequ,_teacherId];
            [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
                if (error) {
                    NSLog(@"************Share fail with error %@*********",error);
                }else{
                    NSLog(@"response data is %@",data);
                }
            }];
        }else{
            
        }
        
    }];
}

-(void)dailNum:(NSString *)num{
    if (!_phone) {
        return;
    }
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",_phone]]];
}

-(void)dailPhone{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",@"025-58115681"]]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)switchBtn:(UIButton *)sender {
    sender.selected = YES;
    switch (sender.tag) {
        case 1001:
            _isShowingMainTable = YES;
            _courseBtn.selected = NO;
            [_detailTableView reloadData];
            break;
        case 1002:
            _isShowingMainTable = NO;
            _mainBtn.selected = NO;
            [_detailTableView reloadData];
            break;
            
        default:
            break;
    }
}


-(void)getteacherbase{
    [hud showAnimated:YES];
    [[ZPNetworking sharedZPNetworking] GET:APISearch@"teacher/getteacherbase.json" parameters:@{@"teacherId":NU(self.teacherId)} progress:nil success:^(id  _Nonnull responseObject) {
        [hud hideAnimated:YES];

        if (CodeIs200(responseObject)) {
            NSDictionary *result = [responseObject objectForKey:@"result"];
            active.text = [NSString stringWithFormat:@"活跃度\n%@",[result objectForKey:@"active"]];
            autograph.text = toStr([result objectForKey:@"autograph"]);
            classPercent.text = [NSString stringWithFormat:@"满班率\n%@％",[result objectForKey:@"classPercent"]];
            constellation.text = [NSString stringWithFormat:@"%@｜学生",[result objectForKey:@"constellation"]];
            enrollsPercent.text = [NSString stringWithFormat:@"续课率\n%@％",[result objectForKey:@"enrollsPercent"]];
            quitPercent.text = [NSString stringWithFormat:@"退课率\n%@％",[result objectForKey:@"quitPercent"]];
            teacherName.text = toStr([result objectForKey:@"teacherName"]);
            stuCount.text = toStr([result objectForKey:@"stuCount"]);
            if (stuCount.text.length==0) {
                stuCount.text=@"0";
            }
            totalScore.text = [NSString stringWithFormat:@"%@分",[result objectForKey:@"totalScore"]];
            [headUrl sd_setImageWithURL:[result objectForKey:@"headUrl"] placeholderImage:Z_IMAGE(@"headportrait")];
            if ([toStr([result objectForKey:@"sex"]) isEqualToString:@"1"]) {
                TSex.image = Z_IMAGE(@"女生符号切片");
            }else{
                TSex.image = Z_IMAGE(@"男生符号切片");
            }

        }else{
            
        }
        [self getteacherhome];
    } failure:^(NSError * _Nonnull error) {
        [self getteacherhome];
        [hud hideAnimated:YES];
    }];
}

-(void)getteacherhome{
    [hud showAnimated:YES];
    [[ZPNetworking sharedZPNetworking] GET:APISearch@"teacher/getteacherhome.json" parameters:@{@"teacherId":NU(self.teacherId)} progress:nil success:^(id  _Nonnull responseObject) {
        [hud hideAnimated:YES];
        if (CodeIs200(responseObject)) {
            NSDictionary *result = [responseObject objectForKey:@"result"];
            teacherHome = result;
            NSMutableDictionary *tmp = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Info",@"type",nil];
            [tmp addEntriesFromDictionary:result];
            [_tableData addObject:tmp];
            [_detailTableView reloadData];
            
        }else{
            
        }
        [self getteacherglorylist];
    } failure:^(NSError * _Nonnull error) {
        [hud hideAnimated:YES];
        [self getteacherglorylist];
    }];
}

-(void)getteacherglorylist{
    [hud showAnimated:YES];
    [[ZPNetworking sharedZPNetworking] GET:APISearch@"teacher/getteacherglorylist.json" parameters:@{@"teacherId":_teacherId} progress:nil success:^(id  _Nonnull responseObject) {
        [hud hideAnimated:YES];
        if (CodeIs200(responseObject)) {
            NSArray *result = [responseObject objectForKey:@"result"];
            honourDArr = [result copy];
            if (result.count>2) {
                result = [result subarrayWithRange:NSMakeRange(0, 2)];
            }
            
            
            if (result.count) {
                [_tableData addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"SHead",@"type",@"荣誉",@"item",@"更多荣誉",@"more",nil]];
            }
            
            for (NSDictionary *tmp in result) {
                NSMutableDictionary *dic = [tmp mutableCopy];
                [dic setObject:@"HuoJiang" forKey:@"type"];
                [dic addEntriesFromDictionary:tmp];
                [_tableData addObject:dic];
            }
            [_detailTableView reloadData];
           
            
        }else{
        }
         [self getteacherclasslist];
    } failure:^(NSError * _Nonnull error) {
        [hud hideAnimated:YES];
         [self getteacherclasslist];
    }];
}

-(void)getteacherclasslist{
    [hud showAnimated:YES];
    [[ZPNetworking sharedZPNetworking] GET:APISearch@"teacher/getteacherclasslist.json" parameters:@{@"teacherId":NU(self.teacherId)} progress:nil success:^(id  _Nonnull responseObject) {
        [hud hideAnimated:YES];
        if (CodeIs200(responseObject)) {

            ////////////////
            _courseTableArray = [responseObject objectForKey:@"result"];
            

            [_courseBtn setTitle:[NSString stringWithFormat:@"课程 %lu",(unsigned long)_courseTableArray.count] forState:UIControlStateNormal];
            [_detailTableView reloadData];
            ////////////////
//            if (result.count) {
//                [_tableData addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"SHead",@"type",nil]];
//            }
//            
//            
//            for (NSDictionary *tmp in result) {
//                NSMutableDictionary *dic = [tmp mutableCopy];
//                [dic setObject:@"DiDian" forKey:@"type"];
//                [dic addEntriesFromDictionary:tmp];
//                [_tableData addObject:dic];
//            }
//            [_detailTableView reloadData];
        }else{
            [_courseBtn setTitle:@"课程 0" forState:UIControlStateNormal];
        }
        [self getEvalList];
    } failure:^(NSError * _Nonnull error) {
        [hud hideAnimated:YES];
        [_courseBtn setTitle:@"课程 0" forState:UIControlStateNormal];
        [self getEvalList];
    }];
}

-(void)getEvalList{
    [hud showAnimated:YES];
    [[ZPNetworking sharedZPNetworking] GET:APISearch@"teacher/getEvalList.json" parameters:@{@"teacherId":_teacherId} progress:nil success:^(id  _Nonnull responseObject) {
        [hud hideAnimated:YES];
        if (CodeIs200(responseObject)) {
            NSArray *result = [responseObject objectForKey:@"result"];
            pingjiaArr = [result copy];
            if (result.count>2) {
                result = [result subarrayWithRange:NSMakeRange(0, 2)];
            }
            if (result.count) {
                [_tableData addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"SHead",@"type",@"评价",@"item",@"更多评价",@"more",nil]];
            }
            
            
            for (NSDictionary *tmp in result) {
                NSMutableDictionary *dic = [tmp mutableCopy];
                [dic setObject:@"PingJia" forKey:@"type"];
                [dic addEntriesFromDictionary:tmp];
                [_tableData addObject:dic];
            }
            [_detailTableView reloadData];

            
        }else{
            [ZPPromptView showMessage:toStr([responseObject objectForKey:@"codeMsg"])];
        }
        [self getSheQu];
    } failure:^(NSError * _Nonnull error) {
        [hud hideAnimated:YES];
        [self getSheQu];
    }];
}

-(void)getSheQu{
    //[_tableData addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"SHead",@"type",@"社区新帖",@"item",nil]];
    [_tableData addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"SheQu",@"type",nil]];
    [_detailTableView reloadData];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (_isShowingMainTable) {
        return _tableData.count;
    }else{
        return _courseTableArray.count;
    }
}

-(CGFloat)heightInfoFor:(NSIndexPath *)indexPath{
    NSDictionary *dic = [_tableData objectAtIndex:indexPath.row];
    if ([dic.allKeys containsObject:@"type"]) {
        NSString *type = [dic objectForKey:@"type"];
        if ([type isEqualToString:@"Info"]) {
            
            NSString *phone = toStr([dic objectForKey:@"teacherPhone"]);
            NSString *weixin = toStr([dic objectForKey:@"wechat"]);
            float p = 0;
            float w = 0;
            if (phone.length==0||([[dic objectForKey:@"showPhone"] boolValue]==NO)) {
                p = 27.0;
            }
            if (weixin.length==0) {
                w= 27.0;
            }
            
            
            return 182-p-w;
        }
        if ([type isEqualToString:@"SHead"]) {
            return 50;
        }
        if ([type isEqualToString:@"DiDian"]) {
            return 140;
        }
        if ([type isEqualToString:@"PingJia"]) {
            float h = ceilf([[[_tableData objectAtIndex:indexPath.row] objectForKey:@"remark"] calculateSize:CGSizeMake(SCREENWIDTH-80, 9999) font:[UIFont systemFontOfSize:11]].height)+59.5;
            return h;
        }
        if ([type isEqualToString:@"HuoJiang"]) {
            return 44;
        }
        if ([type isEqualToString:@"SheQu"]) {
            return cellWebView.frame.size.height;
        }
    }else{
        return 0;
    }
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (_isShowingMainTable) {
        return [self heightInfoFor:indexPath];
    }else{
        return 200;
    }

}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (0 == section) {
        return self.SHeaderView;
    }
    return nil;
}


-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (0==section) {
        return 44;
    }
    return 0;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (_isShowingMainTable) {
        NSDictionary *tmpDic=[_tableData objectAtIndex:indexPath.row];
        NSString *type = [tmpDic objectForKey:@"type"];
        if ([type isEqualToString:@"Info"]) {
            ZPTDTableViewCell01 *cell = [tableView dequeueReusableCellWithIdentifier:@"ZPTDTableViewCell01"];
            cell.wechat.text=toStr([tmpDic objectForKey:@"wechat"]);
            if (cell.wechat.text.length==0) {
                cell.weixinC.constant=0;
                cell.weixinImg.hidden=YES;
            }
            cell.teacherPhone.text=toStr([tmpDic objectForKey:@"teacherPhone"]);
            if (cell.teacherPhone.text.length==0||([[tmpDic objectForKey:@"showPhone"] boolValue]==NO)) {
                cell.phoneC.constant=0;
                cell.phoneImg.hidden=YES;
            }
            cell.grade.text=toStr([tmpDic objectForKey:@"grade"]);;
            cell.schoolName.text= [NSString stringWithFormat:@"%@ %@",toStr([tmpDic objectForKey:@"schoolName"]),[tmpDic objectForKey:@"subject"]];
            cell.contentL.text = toStr([tmpDic objectForKey:@"introduce"]);
            cell.delegate=self;
            _phone =toStr([tmpDic objectForKey:@"teacherPhone"]);
            return cell;
        }
        if ([type isEqualToString:@"SHead"]) {
            ZPTDTableViewCell00 *cell = [tableView dequeueReusableCellWithIdentifier:@"ZPTDTableViewCell00"];
            cell.item.text = [tmpDic objectForKey:@"item"];
            cell.more.hidden=NO;
            cell.arrow.hidden=NO;
            if ([cell.item.text isEqualToString:@"荣誉"] && honourDArr.count<3) {
                cell.more.hidden=YES;
                cell.arrow.hidden=YES;
            }
            if ([cell.item.text isEqualToString:@"评价"] && pingjiaArr.count<3) {
                cell.more.hidden=YES;
                cell.arrow.hidden=YES;
            }
            if ([tmpDic.allKeys containsObject:@"more"]) {
                cell.more.text = [tmpDic objectForKey:@"more"];
            }else{
                cell.more.text=@"更多";
            }
            return cell;
        }
        if ([type isEqualToString:@"DiDian"]) {
            ZPTDTableViewCell03 *cell = [tableView dequeueReusableCellWithIdentifier:@"ZPTDTableViewCell03"];
            cell.className.text=[tmpDic objectForKey:@"className"];
            cell.dateString.text=toStr([tmpDic objectForKey:@"dateString"]);
            cell.needPay.text=toStr([tmpDic objectForKey:@"needPay"]);
            cell.teachName.text=toStr([tmpDic objectForKey:@"teachname"]);
            return cell;
        }
        if ([type isEqualToString:@"PingJia"]) {
            ZPTeacherCmmTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZPTeacherCmmTableViewCell"];
            cell.cmmContent.text = [tmpDic objectForKey:@"remark"];
            if ([[tmpDic objectForKey:@"isAnonymous"] intValue]==1) {
                cell.stuName.text = @"匿名";
                [cell.headUrl setImage:[UIImage imageNamed:@"headportrait"]];
            }else{
                cell.stuName.text = [tmpDic objectForKey:@"stuName"];
                [cell.headUrl sd_setImageWithURL:[tmpDic objectForKey:@"headUrl"] placeholderImage:[UIImage imageNamed:@"headportrait"]];
            }
            
            cell.teachingLevelScore=[[tmpDic objectForKey:@"teachingLevelScore"] intValue];
            cell.updateTime.text = toStr([tmpDic objectForKey:@"updateTime"]);
            return cell;
        }
        if ([type isEqualToString:@"HuoJiang"]) {
            ZPTDTableViewCell02 *cell = [tableView dequeueReusableCellWithIdentifier:@"ZPTDTableViewCell02"];
            cell.picture.hidden = ![[tmpDic objectForKey:@"isPicture"] boolValue];
            cell.text.text = [NSString stringWithFormat:@"%@  %@",[tmpDic objectForKey:@"text"],[tmpDic objectForKey:@"gloryName"]];
            return cell;
        }
        if ([type isEqualToString:@"SheQu"]) {
            
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
            if (![cell.contentView.subviews containsObject:cellWebView]) {
                cell.contentView.backgroundColor = RGBACOLOR(238, 238, 238, 1.);
                [cell.contentView  addSubview:cellWebView];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            
            return cell;
            
                    }
    }else{
        NSDictionary *tmp = [_courseTableArray objectAtIndex:indexPath.row];
        ZPTDTableViewCell11 *cell = [tableView dequeueReusableCellWithIdentifier:@"ZPTDTableViewCell11"];
        cell.delegate=self;
        cell.className.text=toStr([tmp objectForKey:@"className"] );
        cell.teachName.text=toStr([tmp objectForKey:@"teachName"]);
        
        NSString *tmps =toStr([tmp objectForKey:@"needPay"]);
        if (tmps.length) {
            cell.needPay.text=toStr(([NSString stringWithFormat:@"¥%@",tmps]));
        }else{
            cell.needPay.text=@"¥0";
        }
        cell.dateString.text=toStr([tmp objectForKey:@"dateString"]);
        cell.classId=toStr([tmp objectForKey:@"id"]);
        cell.courseId=toStr([tmp objectForKey:@"courseId"]);
        cell.isFull = [[tmp objectForKey:@"isFull"] boolValue];
        cell.priceType = [[tmp objectForKey:@"priceType"] boolValue];
        cell.status = toStr([tmp objectForKey:@"status"]);
        cell.address.text  =toStr([tmp objectForKey:@"address"]);
        return cell;
        
    }
    return nil;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (!_isShowingMainTable) {
        return;
    }
    NSString *type = [[_tableData objectAtIndex:indexPath.row] objectForKey:@"type"];
    if ([[[_tableData objectAtIndex:indexPath.row] objectForKey:@"item"] isEqualToString:@"评价"]||[type isEqualToString:@"PingJia"]) {
        ZPTeacherCommentViewController *vc = [[ZPTeacherCommentViewController alloc]init];
        vc.teacherId=_teacherId;
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([[[_tableData objectAtIndex:indexPath.row] objectForKey:@"item"] isEqualToString:@"荣誉"]||[type isEqualToString:@"HuoJiang"]){
        HonourViewController *vc=[[HonourViewController alloc]init];
        vc.teacherId = _teacherId;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

-(void)showKeBiao:(NSString *)classId courseId:(NSString *)courseId{
    KeBiaoViewController *vc=[[KeBiaoViewController alloc]init];
    vc.classId=classId;
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) {
        vc.modalPresentationStyle=UIModalPresentationOverCurrentContext;
    }else{
        vc.modalPresentationStyle=UIModalPresentationCurrentContext;
    }
    vc.view.backgroundColor = [UIColor colorWithWhite:.0f alpha:.65f];
    [self presentViewController:vc animated:NO completion:nil];
}

- (void)login
{
    ZPRegisterLoginViewController *regLoginVc = [[ZPRegisterLoginViewController alloc] init];
    ZPBaseNavigationController *nvc = [[ZPBaseNavigationController alloc] initWithRootViewController:regLoginVc];
    [self presentViewController:nvc animated:YES completion:nil];
}

- (BOOL)checkLogIn
{
    //已登录过用户资料
    NSMutableDictionary *dataDic = [[ZPAuthStore sharedZPAuthStore] userToDic];
    NSString *token = [dataDic valueForKey:@"token"];
    NSString *memberId = [dataDic valueForKey:@"memberId"];
    if ([token length] <=0 ||[token isEqual:[NSNull null]] || [memberId length] <=0 ||[memberId isEqual:[NSNull null]]) {
        return NO;
    } else {
        
        if ([[ZPAuthEngine sharedZPAuthEngine] isValid]) {
            return YES;
        } else {
            return NO;
        }
    }
}

-(void)baoMingAction:(NSString *)classId courseId:(NSString *)courseId isfull:(BOOL)isfull{
    if (![self checkLogIn]) {// 判断是否登录
        [self login];
        return;
    }
    
    if (isfull) {
//        ComfirmOrderViewController *vc=[[ComfirmOrderViewController alloc]init];
//        vc.courseId=courseId;
//        vc.classId=classId;
//        [self.navigationController pushViewController:vc animated:YES];
        [self initorder:classId andCourseId:courseId];
    }else{
        //[ZPPromptView showMessage:@""];
        return;
    }

}

-(void)goToDetailPage{
    TeacherInfoViewController *vc=[[TeacherInfoViewController alloc]init];
    vc.dic = teacherHome;
    vc.name=teacherName.text;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    //获取到webview的高度
    CGFloat height = [[cellWebView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
    cellWebView.frame = CGRectMake(cellWebView.frame.origin.x,cellWebView.frame.origin.y, cellWebView.frame.size.width, height);
    [_detailTableView reloadData];
}

-(void)initorder:(NSString *)classId andCourseId:(NSString *) courseId{
    [hud showAnimated:YES];
    NSMutableDictionary *paramDic = [NSMutableDictionary dictionary];
    [paramDic setObject:[[[ZPAuthStore sharedZPAuthStore] userToDic] objectForKey:@"memberId"] forKey:@"memberId"];
    [paramDic setObject:[[[ZPAuthStore sharedZPAuthStore] userToDic] objectForKey:@"stuId"] forKey:@"stuId"];
    [paramDic setObject:classId forKey:@"classId"];
    [paramDic setObject:courseId forKey:@"courseId"];
    
    [[ZPNetworking sharedZPNetworking] POST:APIOrder@"/orders/initorder.json" parameters:paramDic progress:nil success:^(id  _Nonnull responseObject) {
        [hud hideAnimated:YES];
        if (CodeIs200(responseObject)) {
            NSDictionary *result = [responseObject objectForKey:@"result"];
            ComfirmOrderViewController *vc=[[ComfirmOrderViewController alloc]init];
            vc.infoDic = [result objectForKey:@"result"];
            vc.courseId=courseId;
            vc.classId=classId;
            vc.priceName = [[result objectForKey:@"result"] objectForKey:@"priceName"];
            [self.navigationController pushViewController:vc animated:YES];
        }else{
            [self alertController:toStr([responseObject objectForKey:@"codeMsg"])];
        }
        
    } failure:^(NSError * _Nonnull error) {
        [hud hideAnimated:YES];
        [ZPPromptView showMessage:error.localizedDescription];
        [self.navigationController popViewControllerAnimated:YES];
    }];
}

- (void)alertController:(NSString *)msg
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:msg preferredStyle:UIAlertControllerStyleAlert];
    
    // 添加按钮
    __weak typeof(alert) weakAlert = alert;
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
       
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"咨询客服" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://02558115681"]];
    }]];
    [self presentViewController:alert animated:YES completion:nil];
}



@end
